//
//  XZTestDetailSecondCell.m
//  Teecloud
//
//  Created by PC on 2018/12/25.
//  Copyright © 2018年 小志. All rights reserved.
//

#import "XZTestDetailSecondCell.h"
#import "XZPostInfos.h"


@interface XZTestDetailSecondCell ()
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@end
#define PerformColor [UIColor colorWithHexString:@"128B03" andAlpha:1.0f]
@implementation XZTestDetailSecondCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setModel:(XZPostInfos *)model{
    _model = model;
    NSString *text = @"";
    if (model.IsPass) {//合格
        NSString *fontText = [NSString stringWithFormat:@"%@，%@分",model.Name,model.Score];
       text = [NSString stringWithFormat:@"%@，%@分（合格），%@，%@",model.Name,model.Score,model.RoomName,model.PostTime];
        [self textAttributedUnString:text scoreString:fontText label:self.titleLabel isPass:true];
    }else{
         NSString *fontText = [NSString stringWithFormat:@"%@，%@分",model.Name,model.Score];
        text = [NSString stringWithFormat:@"%@，%@分（不合格），%@，%@",model.Name,model.Score,model.RoomName,model.PostTime];
        [self textAttributedUnString:text scoreString:fontText label:self.titleLabel isPass:false];
    }
    
}

/*考试未通过 通过*/
- (void)textAttributedUnString:(NSString *)string scoreString:(NSString *)scoreString label:(UILabel *)label isPass:(BOOL)isPass{
    
    NSMutableAttributedString *originalAttributedString = [[NSMutableAttributedString alloc] initWithString:string];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    [originalAttributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, string.length)];
    
    [originalAttributedString addAttribute:NSForegroundColorAttributeName value:kBlackColor range:NSMakeRange(0, scoreString.length)];
    
    //(未通过)
    if (!isPass) {
        [originalAttributedString addAttribute:NSForegroundColorAttributeName value:kRedColor range:NSMakeRange(scoreString.length+1, 3)];
        
    } else {
        [originalAttributedString addAttribute:NSForegroundColorAttributeName value:PerformColor range:NSMakeRange(scoreString.length+1, 2)];
    }
    label.attributedText = originalAttributedString;
}
@end
